package com.lhf.azkaban.springbatch.example.batchlistener;

import com.lhf.azkaban.springbatch.example.exception.MySkipException;
import com.lhf.azkaban.springbatch.example.mode.RepayOrderInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.batch.core.listener.StepListenerSupport;
import org.springframework.batch.item.file.FlatFileParseException;

/**
 * @Author:95780
 * @Date: 15:43 2019/11/21
 * @Description: 对作业步骤的监听实现类
 */
//@Component
public class RepayOrderStepListener extends StepListenerSupport<RepayOrderInfo, RepayOrderInfo> {
    private static final Logger logger = LogManager.getLogger(RepayOrderStepListener.class);

    @Override
    public void onSkipInRead(Throwable t) {
        if (t instanceof FlatFileParseException) {
            FlatFileParseException fpe = (FlatFileParseException) t;
            logger.error("job:{} step:{} reader parse MySkipException. line:{} content:{} MySkipException:{}", "repayOrderJob", "repayOrderStep", fpe.getLineNumber(), fpe.getInput(), fpe.getMessage());
        } else {
            logger.error("job:{} step:{} reader 未知错误.{}", "repayOrderJob", "repayOrderStep", t);
        }

    }

    @Override
    public void afterRead(RepayOrderInfo item) {
    }

    @Override
    public void onSkipInProcess(RepayOrderInfo item, Throwable t) {
        if (t instanceof MySkipException) {
            logger.error("job:{} step:{} process skip Data. content:{} exception:{}", "repayOrderJob", "repayOrderStep", item, t.getMessage());
        } else {
            logger.error("job:{} step:{} process 未知错误.", "repayOrderJob", "repayOrderStep", t);
        }

    }

    @Override
    public void onSkipInWrite(RepayOrderInfo item, Throwable t) {
        logger.error("job:{} step:{} writer 未知错误.", "repayOrderJob", "repayOrderStep", t);
    }

}
